<template>
  <el-container class="home-container">
    <el-header class='header'>
      <h1>企业劳动关系管理系统</h1>
<!--      <el-button class='header-btn' type="info" @click="logout">退出</el-button>-->
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle-button" @click="toggle">|||</div>
       <el-menu
      class="el-menu-vertical-demo"
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff"

      :collapse="isCollapse"
      :default-active="activePath"
      :collapse-transition="false"
      :router="true"
      >
      <el-submenu :index="item.id+``" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i :class="iconObj[item.id]"></i>
          <span>{{item.authName}}</span>
        </template>
        <el-menu-item v-for="child in item.children" :key="child.id" :index="'/'+child.path" @click="saveNavState('/'+child.path)">
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{child.authName}}</span>
          </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
      </el-aside>
      <el-main class='main-container'>
        <router-view :isHr='isHr'></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
//清空token
//跳转至登录页
export default {
  async created() {
    this.activePath = window.sessionStorage.getItem("activePath")
    this.isHr=window.sessionStorage.getItem('isHr')
    await this.getMenuList()
  },
  data(){
    return{
      menuList:[],
      iconObj:{
      '125':'el-icon-user',
      '103':'el-icon-s-contract',
      '102':'el-icon-coordinate',
      '101':'el-icon-document',
      '145':'el-icon-document'},
      isCollapse:false,
      isHr: false,
      activePath:''
    }
  },
  methods: {
    logout: function () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    getMenuList:async function(){
      if(this.isHr==='true'){
        this.menuList=[
          {
            "id": 125,
            "authName": "人员管理",
            "path": "users",
            "children": [
              {
                "id": 110,
                "authName": "职员管理",
                "path": "users",
                "children": [],
                "order": null
              },
              {
                "id": 111,
                "authName": "离职管理",
                "path": "userLeave",
                "children": [],
                "order": null
              },
            ],
            "order": 1
          },
          {
            "id": 101,
            "authName": "合同管理",
            "path": "contract",
            "children": [
              {
                "id": 104,
                "authName": "查看合同",
                "path": "contract",
                "children": [],
                "order": 1
              }
            ],
            "order": 3
          },
          {
            "id": 102,
            "authName": "补贴管理",
            "path": "allowance",
            "children": [
              {
                "id": 107,
                "authName": "补助申领",
                "path": "allowance",
                "children": [],
                "order": null
              }
            ],
            "order": 4
          }
        ]
      }
      else{
        this.menuList=[
          {
            "id": 125,
            "authName": "人员操作",
            "path": "users",
            "children": [
              {
                "id": 111,
                "authName": "提交离职",
                "path": "staffLeave",
                "children": [],
                "order": null
              },
            ],
            "order": 1
          },
          {
            "id": 101,
            "authName": "合同管理",
            "path": "staffGeneral",
            "children": [
              {
                "id": 104,
                "authName": "我的合同",
                "path": "staffGeneral",
                "children": [],
                "order": 1
              }
            ],
            "order": 3
          },
          {
            "id": 102,
            "authName": "补贴管理",
            "path": "allowance",
            "children": [
              {
                "id": 107,
                "authName": "补助申领",
                "path": "staffAllowance",
                "children": [],
                "order": null
              }
            ],
            "order": 4
          }
        ]
      }
      console.log(this.menuList);
    },
    toggle:function(){
      this.isCollapse=!this.isCollapse;
    },
    // 保存链接激活状态
    saveNavState:function(activePath){
      window.sessionStorage.setItem("activePath",activePath)
      this.activePath=activePath
    }
  },
}
</script>
<style lang="less" scoped>
  /deep/.main-container{
    background-color:#fff;
    height:100%;
    padding:0;
  }
.header{
  display: flex;
  color: #eeeeee;
  .header-btn{
    margin-left: 20px;
    height: 60%;
    align-self: center;
  }
}
.home-container{
  height: 100%;
}
.el-header{
  background-color: #373d41;
}
.el-aside{
  background-color: #333744;
}
.el-main{
  background-color: #eaedf1;
}
i{
  margin-right: 10px;
}
.el-menu{
  border-right: none;
}
.toggle-button{
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  text-align: center;
  color: #fff;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
